package com.dao;

import java.sql.Timestamp;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.base.BaseDao;
import com.base.UserBean;
import com.bean.ParkComment;

/**
 	* A data access object (DAO) providing persistence and search support for ParkComment entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see com.bean.ParkComment
  * @author MyEclipse Persistence Tools 
 */
public class ParkCommentDao extends BaseDao  {
	     private static final Logger log = Logger.getLogger(ParkCommentDao.class);
		//property constants
	public static final String CONTENT = "content";
	public static final String OPT1 = "opt1";
	public static final String OPT2 = "opt2";
	public static final String OPT3 = "opt3";
	public static final String OPT4 = "opt4";
	public static final String OPT5 = "opt5";
	public static final String STATUS = "status";



    
    public void save(ParkComment transientInstance) {
        log.debug("saving ParkComment instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(ParkComment persistentInstance) {
        log.debug("deleting ParkComment instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public ParkComment findById( java.lang.Long id) {
        log.debug("getting ParkComment instance with id: " + id);
        try {
            ParkComment instance = (ParkComment) getSession()
                    .get(ParkComment.class, id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(ParkComment instance) {
        log.debug("finding ParkComment instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.dao.ParkComment")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding ParkComment instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from ParkComment as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByContent(Object content
	) {
		return findByProperty(CONTENT, content
		);
	}
	
	public List findByOpt1(Object opt1
	) {
		return findByProperty(OPT1, opt1
		);
	}
	
	public List findByOpt2(Object opt2
	) {
		return findByProperty(OPT2, opt2
		);
	}
	
	public List findByOpt3(Object opt3
	) {
		return findByProperty(OPT3, opt3
		);
	}
	
	public List findByOpt4(Object opt4
	) {
		return findByProperty(OPT4, opt4
		);
	}
	
	public List findByOpt5(Object opt5
	) {
		return findByProperty(OPT5, opt5
		);
	}
	
	public List findByStatus(Object status
	) {
		return findByProperty(STATUS, status
		);
	}
	
	//where parkOrder.parkinfo.PId in (select PId from ParkinfoManagerRelevance where userId=?)
	public List<ParkComment> findAll(ParkComment comment,UserBean bean) {
		log.debug("finding all ParkComment instances");
		try {
			String queryString = "from ParkComment";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public ParkComment merge(ParkComment detachedInstance) {
        log.debug("merging ParkComment instance");
        try {
            ParkComment result = (ParkComment) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(ParkComment instance) {
        log.debug("attaching dirty ParkComment instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(ParkComment instance) {
        log.debug("attaching clean ParkComment instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}